#include "PyrolysisRhoKernel.h"
#include<iostream>
using std::cout;
using std::endl;
registerMooseObject("TrilobitaApp", PyrolysisRhoKernel);
template<>
InputParameters validParams<PyrolysisRhoKernel>()
{
  InputParameters params = validParams<TimeKernel>();
  params.addParam<std::string>("rho_name", "Material property density name");
  params.addClassDescription("Compute rho_x kernel ");
  params.addRequiredCoupledVar("temperature", "Coupled Temperature");
  return params;
}

PyrolysisRhoKernel::PyrolysisRhoKernel(const InputParameters & parameters) :
		TimeKernel(parameters),
  _rho_name(isParamValid("rho_name") ? getParam<std::string>("rho_name") : ""),
  _pyrolysis_source(getMaterialProperty<Real>("pyrolysis_source"+_rho_name)),
  _dsource_drho(getMaterialProperty<Real>("dsource_drho"+_rho_name)),
  _dsource_dT(getMaterialProperty<Real>("dsource_dT"+_rho_name)),
  _T_num(coupled("temperature"))

{
}

Real PyrolysisRhoKernel::computeQpResidual()
{
//	std::cout << _k[_qp] <<std::endl;

  Real r(0);
//  cout<<_pyrolysis_source[_qp]<<std::endl;
//  cout<<_T_num<<std::endl;
  r = _u_dot[_qp]*_test[_i][_qp]+_pyrolysis_source[_qp]* _test[_i][_qp];
  return r;
}

Real PyrolysisRhoKernel::computeQpJacobian()
{
  Real jac(0);
  jac = _test[_i][_qp]*_phi[_j][_qp]*_du_dot_du[_qp]+_dsource_drho[_qp]*_phi[_j][_qp]* _test[_i][_qp];
  return jac;
}

Real PyrolysisRhoKernel::computeQpOffJacobian(unsigned int jvar)
{
	if ( jvar == _T_num)
	{
		return _dsource_dT[_qp]* _u_dot[_qp] * _test[_i][_qp];
	}
	else
	{
		return 0 ;
	}
}



